﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kokomo.Lexical.Expressions;

namespace Kokomo.PeInspector.Reflection.Disassembly
{
	/// <summary>
	/// Represents a reference to a variable from MSIL.
	/// </summary>
	public class MsilVariableReference
	{
		/// <summary>
		/// Gets the variable referenced.
		/// </summary>
		public Variable Variable { get; private set; }
		/// <summary>
		/// Gets the offset of the instruction referencing the variable.
		/// </summary>
		public int Offset { get; private set; }
		/// <summary>
		/// Gets the type of variable reference.
		/// </summary>
		/// <seealso cref="MsilVariableReferenceType"/>
		public MsilVariableReferenceType Type { get; private set; }

		/// <summary>
		/// Initializes a new instance of <see cref="MsilVariableReference"/>.
		/// </summary>
		/// <param name="variable">The variable referenced.</param>
		/// <param name="offset">The offset of the instruction referencing the variable.</param>
		/// <param name="type">The type of variable reference.</param>
		public MsilVariableReference(
			Variable variable,
			int offset,
			MsilVariableReferenceType type
			)
		{
			if (variable == null) throw new ArgumentNullException("variable");

			this.Variable = variable;
			this.Offset = offset;
			this.Type = type;
		}

		public override string ToString()
		{
			return string.Format("{0:X4}: {1}", this.Offset, this.Variable);
		}
	}
}
